$(document).ready(function() {
	$("footer .glyphicon-refresh").click(function() {
		location.reload();
	})

	$("footer .glyphicon-arrow-left").click(function() {
		history.go(-1);
	})

	

});

function goUrl(url) {
	window.location.href = url;
}

function myConfirm(title,content,ensureText,ensuredCallback){
    var myConfirmCode = '<div class="modal fade" id="myConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
                  <div class="modal-dialog">\
                    <div class="modal-content">\
                      <div class="modal-header">\
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
                        <h4 class="modal-title" id="myModalLabel">'+title+'</h4>\
                      </div>\
                      <div class="modal-body">\
                        '+content+'\
                      </div>\
                      <div class="modal-footer">\
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\
                        <button type="button" class="btn btn-danger">'+ensureText+'</button>\
                      </div>\
                    </div>\
                  </div>\
                </div>';
    if($("#myConfirm").length==0){
        $("body").append(myConfirmCode);
    }      
    $('#myConfirm').modal();
    $('#myConfirm button.btn-danger').unbind("click","");
    $('#myConfirm button.btn-danger').click(function (event) {
        if (ensuredCallback)
            ensuredCallback();
        $('#myConfirm').modal('hide')
    });
}



function alert_h(content,ensuredCallback) {
    var myConfirmCode = '<div class="modal fade" id="alert_h" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
                  <div class="modal-dialog">\
                    <div class="modal-content">\
                      <div class="modal-header">\
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
                        <h4 class="modal-title" id="myModalLabel">操作提示</h4>\
                      </div>\
                      <div class="modal-body">\
                        '+content+'\
                      </div>\
                      <div class="modal-footer">\
                        <button type="button" class="btn btn-primary" data-dismiss="modal">确认</button>\
                      </div>\
                    </div>\
                  </div>\
                </div>';


    if ($("#alert_h").length != 0) {
        $('#alert_h').remove();
    }
    $("body").append(myConfirmCode);
    $('#alert_h').modal();
    $('#alert_h').off('hide.bs.modal').on('hide.bs.modal', function (e) {
        if (ensuredCallback)
            ensuredCallback();
    });
}


var pageLoadTime;

function GetRTime(){
     var d;
     var h;
     var m;
     var s;

     var startVal=document.getElementById("startTime").value;
     var endVal=document.getElementById("endTime").value;
     var startTime=new Date(startVal);
     var endTime= new Date(endVal); //截止时间 前端路上 http://www.51xuediannao.com/qd63/
     var nowTime = new Date();
     var now_startTime=nowTime.getTime()-startTime.getTime();    //当前时间 减去开始时间
     var s_nTime=startTime.getTime()-nowTime.getTime();          //开始时间减去当前时间
     var start_endTime=endTime.getTime()-startTime.getTime();    //结束时间减去开始时间
     var now_endTime =endTime.getTime() - nowTime.getTime();     //结束时间减去当前时间
     var now_pTime=nowTime.getTime()-pageLoadTime;               //当前时间减去页面刷新时间
     var p_sTime=startTime.getTime()-pageLoadTime;               //开始时间减去页面刷新时间
     var wid=now_startTime/start_endTime*100;                    //开始后离结束的时间比
     var wid1=now_pTime/p_sTime*100;                             //未开始离开始的时间比
     var tuan_button = document.getElementById("buyButton");
     var progress=document.getElementById("progress");
     var tuan_time=document.getElementById("tuan_time");
     function docu(){
       document.getElementById("t_d").innerHTML = d+"天";
       document.getElementById("t_h").innerHTML = h+"时";
       document.getElementById("t_m").innerHTML = m+"分";
       document.getElementById("t_s").innerHTML = s+"秒";
     }
     if(pageLoadTime==null){
        pageLoadTime=new Date();
     }
    if(100>=wid1>=0 && wid<0){
      d=Math.floor(Math.abs(now_startTime)/1000/60/60/24);
      h=Math.floor(Math.abs(now_startTime)/1000/60/60%24);
      m=Math.floor(Math.abs(now_startTime)/1000/60%60);
      s=Math.floor(Math.abs(now_startTime)/1000%60);
      docu();
      tuan_time.innerHTML="团购开始时间：";
      progress.style.width=wid1+"%";
      tuan_button.disabled=true;
    }
    if(wid1>100||wid1<0){
      if(wid >=0 && wid < 70){
        d=Math.floor(now_endTime/1000/60/60/24);
        h=Math.floor(now_endTime/1000/60/60%24);
        m=Math.floor(now_endTime/1000/60%60);
        s=Math.floor(now_endTime/1000%60);
        docu();
        tuan_time.innerHTML="团购结束时间：";
        progress.style.width=(100-wid)+"%";
        tuan_button.disabled=false;
      }else if(wid >=70 && wid < 90){
        d=Math.floor(now_endTime/1000/60/60/24);
        h=Math.floor(now_endTime/1000/60/60%24);
        m=Math.floor(now_endTime/1000/60%60);
        s=Math.floor(now_endTime/1000%60);
        docu();
        tuan_time.innerHTML="团购结束时间：";
        progress.className ="progress-bar progress-bar-warning";
        progress.style.width=(100-wid)+"%";
        tuan_button.disabled=false;
      }else if(wid >=90 && wid <= 100){
        d=Math.floor(now_endTime/1000/60/60/24);
        h=Math.floor(now_endTime/1000/60/60%24);
        m=Math.floor(now_endTime/1000/60%60);
        s=Math.floor(now_endTime/1000%60);
        docu();
        tuan_time.innerHTML="团购结束时间：";
        progress.style.width=(100-wid)+"%";
        progress.className ="progress-bar progress-bar-danger";
        tuan_button.disabled=false;
      }

      if(wid>100){
        tuan_time.innerHTML="团购已结束!";
        progress.style.width=0;
        tuan_button.disabled=true;
      }
    }

    

    /* 

    if(now_startTime>0&&t>0){
         document.getElementById("progress").style.width=wid+"%";
         document.getElementById("t_d").innerHTML = d+"天";
         document.getElementById("t_h").innerHTML = h+"时";
         document.getElementById("t_m").innerHTML = m+"分";
         document.getElementById("t_s").innerHTML = s+"秒";
     }
     
    */

     /*var d=Math.floor(t/1000/60/60/24);
     t-=d*(1000*60*60*24);
     var h=Math.floor(t/1000/60/60);
     t-=h*60*60*1000;
     var m=Math.floor(t/1000/60);
     t-=m*60*1000;
     var s=Math.floor(t/1000);*/
}

function loadIframeURL(url) {
    var iFrame;
    iFrame = document.createElement("iframe");
    iFrame.setAttribute("src", url);
    iFrame.setAttribute("style", "display:none;");
    iFrame.setAttribute("height", "0px");
    iFrame.setAttribute("width", "0px");
    iFrame.setAttribute("frameborder", "0");
    document.body.appendChild(iFrame);
    // 发起请求后这个iFrame就没用了，所以把它从dom上移除掉
    //iFrame.parentNode.removeChild(iFrame);
    iFrame = null;
}

function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
        else return ""
    }
} 

var browser = {
    versions: function () {
        var u = navigator.userAgent, app = navigator.appVersion;
        return { //移动终端浏览器版本信息 
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 
            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器 
            iPad: u.indexOf('iPad') > -1, //是否iPad 
    };
}(),
}
    //1代表ios，2代表安卓，3代表其他
    function GetAgentType() {
        if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
            return 1;
        }else if(browser.versions.android){
            return 2;
        }else {
            return 3;
        }
    }
 
